import cv2
import matplotlib.pyplot as plt

img = cv2.imread('C:/Users/nic/Desktop/opencv/picture/cat.JPG')
top_size,bottom_size,left_size,right_size = (50,50,50,50)

#把图片以相应的方式来进行扩充（哪个图片，顶部，底部，左边，右边分别扩充多少，以及怎么扩充）
replicate = cv2.copyMakeBorder(img , top_size,bottom_size,left_size,right_size, borderType=cv2.BORDER_REPLICATE)  #复制法，直接复制最边缘的像素
reflect = cv2.copyMakeBorder(img , top_size,bottom_size,left_size,right_size, borderType=cv2.BORDER_REFLECT)      #反射法，
reflect101 = cv2.copyMakeBorder(img , top_size,bottom_size,left_size,right_size, borderType=cv2.BORDER_REFLECT_101)
wrap = cv2.copyMakeBorder(img , top_size,bottom_size,left_size,right_size, borderType=cv2.BORDER_WRAP)
constant = cv2.copyMakeBorder(img , top_size,bottom_size,left_size,right_size, borderType=cv2.BORDER_CONSTANT, value=0)


plt.subplot(231),plt.imshow(img,'gray'),plt.title('ORIGINAL')
plt.subplot(232),plt.imshow(replicate,'gray'),plt.title('replicate')
plt.subplot(233),plt.imshow(reflect,'gray'),plt.title('reflect')
plt.subplot(234),plt.imshow(reflect101,'gray'),plt.title('reflect101')
plt.subplot(235),plt.imshow(wrap,'gray'),plt.title('wrap')
plt.subplot(236),plt.imshow(constant,'gray'),plt.title('constant')

plt.show()
